package com.efast.dmom.aps.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.efast.dmom.aps.bean.ProductionLine;
import com.efast.dmom.aps.bean.ResultBean;
import com.efast.dmom.aps.entity.base.IModificationFlags;
import com.efast.dmom.aps.service.ProductionLineService;

@Controller
@RequestMapping(value = "/ProductionLine")
public class ProductionLineController  {

	@Autowired
	private ProductionLineService productionLineService;
	
	@RequestMapping(value = "/operateByProductionLine")
	public @ResponseBody ResultBean operateByProductionLine (@RequestBody ProductionLine productionLine) {
		ResultBean resultBean = new ResultBean(true, ' ');
		// Determine the new
		if (productionLine.getInnerData().getModificationFlag() == IModificationFlags.NEW) {
			resultBean = productionLineService.save(productionLine);
			// Judge update
		} else if (productionLine.getInnerData().getModificationFlag() == IModificationFlags.MODIFIED) {
			resultBean = productionLineService.update(productionLine);
			// Judge to delete
		} else if (productionLine.getInnerData().getModificationFlag() == IModificationFlags.DELETED) {
			resultBean = productionLineService.delete(productionLine);
		}
		return resultBean;
	}
	
	//get all productionLine
	@RequestMapping(value = "/getAllProductionLine")
	public @ResponseBody List<ProductionLine> getAllProductionLine() {
		return productionLineService.getAllProductionLine();
	}
	@RequestMapping(value = "/queryCodeIdNameByWorkshopId/{workshopId}")
	public @ResponseBody ResultBean queryCodeIdNameByWorkshopId(@PathVariable Long workshopId) {
		ResultBean resultBean = new ResultBean(true);
		resultBean.setObject(productionLineService.queryCodeIdNameByWorkshopId(workshopId));
		return resultBean;
	}
	
}
